import request from "@/utils/request";

const BASE_URL = "/api/admin";

const ArticleAPI = {
  getCateArticleCount() {
    return request<any, any>({
      url: `${BASE_URL}/getCateArticleCount`,
      method: "get",
    });
  },
  /**
   * 添加文章
   */
  addArticle(article) {
    // 接口返回字段：{code,data,msg} ,其中  request<any, data的类型>
    return request<any, any>({
      url: `${BASE_URL}/addArticle`,
      data: article,
      method: "post",
    });
  },

  getAllTag() {
    return request<any, any>({
      url: `${BASE_URL}/tagList`,
      method: "get",
    });
  },
  /**
   * 获取分页文章
   */
  fetchArticle({ page, pagesize }: QueryArticle) {
    // 接口返回字段：{code,data,msg} ,其中  request<any, data的类型>
    return request<any, ArticlePageData>({
      url: `${BASE_URL}/article`,
      params: { page, pagesize },
      method: "get",
    });
  },
};

export default ArticleAPI;

export interface QueryArticle {
  page: number;
  pagesize: number;
}

export interface ArticlePageData {
  article: Article[];
  count: number;
}

export interface Article {
  article_id: number;
  title: string;
  content: string;
  publish_date: string;
  intro: string;
  views: number;
  status: boolean;
  cover: string;
  tag_ids: string;
  is_admin: boolean;
  category_id: number;
  category_name: string;
  add_date: string;
  update_date: string;
  user_id: number;
  admin_id: number;
  good_count: number;
}
